package com.jiangyao.controller;


import com.jiangyao.common.ApiResult;
import com.jiangyao.common.exception.ServerException;
import com.jiangyao.model.dto.SubmitCourseQuestionDTO;
import com.jiangyao.model.dto.SubmitQuestionDTO;
import com.jiangyao.model.vo.AnAuditionQuestionVo;
import com.jiangyao.model.vo.QuestionVo;
import com.jiangyao.model.vo.SubmitQuestionVo;
import com.jiangyao.service.QuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.jiangyao.controller.BaseController;

/**
 * <p>
 * 试题信息表 前端控制器
 * </p>
 *
 * @author zhoushuangxiang
 * @since 2020-08-18
 */
@RestController
@RequestMapping("/question")
@Api(tags = "答题相关接口")
public class QuestionController extends BaseController {

    @Autowired
    private QuestionService questionService;

    @ApiOperation(value = "获取面试试题",notes = "选填字段：orgName")
    @GetMapping("/getQuestion")
    public ApiResult getQuestion(@RequestParam(value = "questionId",required = true) String questionId){
        try {
            AnAuditionQuestionVo questionVo=questionService.getQuestion(questionId);
            return ApiResult.success(questionVo);
        } catch (ServerException e) {
            return ApiResult.error(e.getCode(),e.getMessage());
        }
    }

    @ApiOperation(value = "提交面试试题")
    @PostMapping("/submitQuestion")
    public ApiResult submitQuestion(@Validated @RequestBody SubmitQuestionDTO submitQuestionDTO){
        try {
            return ApiResult.success(questionService.submitQuestion(submitQuestionDTO));
        } catch (ServerException e) {
            return ApiResult.error(e.getCode(),e.getMessage());
        }
    }

    @ApiOperation("提交学习课程的面试试题")
    @PostMapping("/submitCourseQuestion")
    public ApiResult<SubmitQuestionVo> submitCourseQuestion(@Validated @RequestBody SubmitCourseQuestionDTO submitCourseQuestionDTO){

        return ApiResult.success(questionService.submitCourseQuestion(submitCourseQuestionDTO));
    }


}

